<template>
  <section>
    <!--工具条-->
    <el-col :span="24"
      class="toolbar"
      style="text-align: center;">
      <el-form :inline="true"
        :model="filters">
        <el-form-item label="应用标识(id)">
          <el-input v-model="filters.appCode"
            placeholder="查询此应用下的所有服务"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
            @click="getSv">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table :data="appliedSvInfo"
      highlight-current-row
      v-loading="listLoading"
      style="width: 95%;margin:auto;">
      <el-table-column prop="appCode"
        label="应用标识">
      </el-table-column>
      <el-table-column prop="apiCode"
        label="服务标识">
      </el-table-column>
      <el-table-column prop="apiName"
        label="服务名称">
      </el-table-column>
      <el-table-column prop="originalUri"
        label="网关访问路径">
      </el-table-column>
      <el-table-column label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button round
            @click="cancelApply(scope.row)">取消申请</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination layout="prev, pager, next"
      v-if="pageTotal2>10"
      @current-change="handleCurrentChange"
      style="margin:10px;text-align: center;"
      :total="pageTotal2">
    </el-pagination>
  </section>
</template>

<script>
import { getService, cancelService } from "@/api/allApi"; // 引入相应API

export default {
  data() {
    return {
      page: 1,
      pageTotal2: 1,
      filters: {
        appCode: ""
      },
      searchCode:'',
      appliedSvInfo: [],
      listLoading: false,
      visible1: false,
      addLoading: false
    };
  },
  methods: {
    handleCurrentChange(val) {
      this.page = val;
      let params = {
        appCode: this.searchCode,
        currentPage: this.page,
        pageSize: 10,
        type: "1"
      };
      this.getSvtable(para);
    },
    //查询passId
    getSv() {
      let para = {
        appCode: this.filters.appCode,
        currentPage: 1,
        pageSize: 10,
        type: "1"
      };
      this.getSvtable(para);
      this.searchCode = this.filters.appCode;
    },
    cancelApply(row) {
      this.$confirm("是否取消申请?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let param = {
            subId: row.subId
          };
          console.log(row.subId);
          cancelService(param).then(res => {
            if (res.data.code === "0") {
              this.$msgbox({
                title: "提示",
                message: "已取消订阅！",
                callback: () => {
                  location.reload();
                }
              });
            } else {
              this.$message.error(res.data.desc);
            }
          });
        })
        .catch(() => {});
    },
    getApplied() {
      this.listLoading = true;
      let params = {
        currentPage: 1,
        pageSize: 10,
        type: "1"
      };
      this.getSvtable(params);
    },
    getSvtable(param) {
      this.listLoading = true;
      getService(param).then(res => {
        if (res.data.code === "0") {
          this.pageTotal2 = res.data.data.pageTotal;
          this.appliedSvInfo = res.data.data.pageData;
        } else {
          this.$message({
            message: `[${res.data.desc}]:查询失败`,
            type: "error"
          });
        }
        this.listLoading = false;
      });
    }
  },
  mounted() {
    this.getApplied();
  }
};
</script>

<style scoped>
</style>